package com.hfkh.keyun.controller.frontend;

import com.hfkh.keyun.common.ApiResult;
import com.hfkh.keyun.entity.Collect;
import com.hfkh.keyun.service.CollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/app/collect")
@Api(tags = "收藏管理")
public class CollectControllerApp {

    @Resource
    private CollectService collectService;


    @ApiOperation(" 查询个人收藏表单")
    @GetMapping("/selCollectList")
    public ApiResult selectCollectList(Integer userId){
        List<Collect> collectList = collectService.selCollectList(userId);
        return ApiResult.success(collectList);
    }


    @ApiOperation(" 根据id删除")
    @DeleteMapping("/deleteById")
    public ApiResult deleteCollect(@RequestParam Integer id){
        collectService.removeById(id);
        return ApiResult.ok("删除成功！", "头像上传成功！");
    }


    @ApiOperation(" 批量删除")
    @DeleteMapping("/deleteBatch")
    public ApiResult deleteCollectBatch(@RequestBody Integer[] ids){
        boolean b = collectService.removeBatchByIds(Arrays.asList(ids));
        return ApiResult.ok("批量删除成功！", "头像上传成功！");
    }


    //有问题
    /*   *//**
     * 收藏课程
     * @param
     * @return
     *//*
    @PostMapping("/addCollect")
    public ApiResult addCollect(CollectVO collectVo){
        Collect collect=new Collect();
        List<Collect> collectList = collectService.selCollectList(collectVo.getUserId());
        BeanUtils.copyProperties(collectVo,collect);
        collect.setDeleteFlags(0);
        Boolean isFlay=true;
        for (Collect collect1 : collectList) {
            if(Objects.equals(collectVo.getId(), collect1.getId())){
                isFlay=true;
            }else {
                isFlay=false;
            }
        }
        if(isFlay){
            collectService.updateById(collect);
            return ApiResult.ok("收藏成功");
        }else {
            collectService.save(collect);
            return ApiResult.ok("添加收藏成功");
        }
    }*/
}
